 
package com.hs.utils;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;

import com.hs.log.HsLogger;

/**
 * This class acts as a utility class for providing the capability of a property file
 * that is sorted alphabetically by key value.  It is useful for things like translation
 * files where having the file in a logical order is useful for maintainers.
 */
public class SortedProperties extends Properties {

	/** Logger */
	public static final HsLogger logger = HsLogger.getLogger(SortedProperties.class.getName());

	/**
	 * Standard constructor for creating a sorted properties file.
	 */
	public SortedProperties() {
		super();
	}

	/**
	 * Copy constructor used to create a sorted properties file.
	 */
	public SortedProperties(Properties properties) {
		super();
		this.putAll(properties);
	}

	/**
	 * Override the Properties.keys() method so that the keyset returned is sorted.
	 */
	public Enumeration keys() {
		Enumeration keyEnum = super.keys();
		Vector keys = new Vector();
		while (keyEnum.hasMoreElements()) {
			keys.add(keyEnum.nextElement());
		}
		Collections.sort(keys);
		return keys.elements();
	}
}
